﻿using System.Text.RegularExpressions;
using UnityEngine;
/// <summary>
/// 超文本扩展
/// </summary>
public static class ESF_RichTextExtendEngine
{
    #region ApplyBold 将文本加粗
    /// <summary>
    /// 将文本加粗
    /// </summary>
    /// <param name="_text">文本</param>
    /// <param name="_color">颜色</param>
    /// <returns>文本</returns>
    public static string ESF_ApplyBold(this object _text)
    {
        return string.Format("<b>{0}</b>", _text);
    }
    #endregion

    #region ApplyItalic 将文本斜体
    /// <summary>
    /// 将文本斜体
    /// </summary>
    /// <param name="_text">文本</param>
    /// <param name="_color">颜色</param>
    /// <returns>文本</returns>
    public static string ESF_ApplyItalic(this object _text)
    {
        return string.Format("<i>{0}</i>", _text);
    }
    #endregion    

    #region ApplyColor 将文本加上颜色标记
    /// <summary>
    /// 将文本加上颜色标记
    /// </summary>
    /// <param name="_text">文本</param>
    /// <param name="_color">颜色</param>
    /// <returns>文本</returns>
    public static string ESF_ApplyColor(this object _text, Color _color)
    {
        return string.Format("<color={0}>{1}</color>", _color.ESF_ToRGB(), _text);
    }

    /// <summary>
    /// 将Format格式化文本加上颜色标记
    /// </summary>
    /// <param name="_format">格式化</param>
    /// <param name="_color">颜色</param>
    /// <param name="_args">参数</param>
    /// <returns>文本</returns>
    public static string ESF_FormatApplyColor(this string _format, Color _color, params object[] _args)
    {
        return string.Format("<color={0}>{1}</color>", _color.ESF_ToRGB(), string.Format(_format, _args));
    }
    #endregion

    #region ApplyHyperlink 将文本变为超链接
    /// <summary>
    /// 将文本变为超链接
    /// </summary>
    /// <param name="_path">超链接</param>
    /// <returns>文本</returns>
    public static string ESF_ApplyHyperlink(this object _path)
    {
        return _path.ESF_ApplyHyperlink(_path);
    }

    /// <summary>
    /// 将文本变为超链接
    /// </summary>
    /// <param name="_text">文本</param>
    /// <param name="_path">超链接</param>
    /// <returns>文本</returns>
    public static string ESF_ApplyHyperlink(this object _text, object _path)
    {
        return string.Format("<a herf=\"{0}\">{1}</a>", _path, _text);
    }
    #endregion    

    #region ESF_ClearHTMLMark 清除所有HTML标签
    /// <summary>
    /// 清除所有HTML标签
    /// </summary>
    /// <param name="_text">文本</param>
    /// <returns>文本</returns>
    public static string ESF_ClearHTMLMark(this object _text)
    {
        return Regex.Replace(_text.ToString(), @"(<([^>]+)>)", "");
    }
    #endregion
}

